<?php

  require_once "JooS/UCS2/Interface.php";

  class JooS_UCS2 implements JooS_UCS2_Interface {
    private static $_charTable = null;

    public function __construct() {
    }

    public function convertString($str) {
      return $str;
    }
    
    public static function convert($str) {
      return self::getInstance()->convertString($str);
    }

    private static function getInstance() {
      if (null === self::$_charTable) {
        $charset = ini_get('default_charset');
        if (!$charset)
          self::throwException('ini_set("default_charset", "...");');

        require_once "Zend/Loader.php";
        $className = __CLASS__ . "_" . str_replace("-", "_", strtoupper($charset));
        try {
          Zend_Loader::loadClass($className);
        }
        catch (Zend_Exception $e) {
          $className = __CLASS__;
        }

        $rClass = new ReflectionClass($className);
        if (!$rClass->implementsInterface("JooS_UCS2_Interface"))
          self::throwException("class $className must be a subclass of JooS_UCS2");

        self::$_charTable = $rClass->newInstance();
      }
      return self::$_charTable;
    }

    protected static function throwException($message, $code = 0) {
      require_once 'JooS/UCS2/Exception.php';
      throw new JooS_UCS2_Exception($message, $code);
    }
  }

?>